package com.neusoft.resturant.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.neusoft.resturant.common.utils.PageResult;
import com.neusoft.resturant.common.utils.PageUtils;
import com.neusoft.resturant.entity.ResRemark;
import com.neusoft.resturant.mapper.ResRemarkMapper;
import com.neusoft.resturant.service.IResRemarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 评价
Service业务层处理
 * 
 * @author lzx
 * @date 2023-12-18
 */
@Service
public class ResRemarkServiceImpl implements IResRemarkService
{
    @Autowired
    private ResRemarkMapper resRemarkMapper;

    /**
     * 查询评价

     * 
     * @param id 评价
主键
     * @return 评价

     */
    @Override
    public ResRemark selectResRemarkById(Long id)
    {
        return resRemarkMapper.selectResRemarkById(id);
    }

    /**
     * 查询评价
列表
     * 
     * @param resRemark 评价

     * @return 评价

     */
    @Override
    public PageResult selectResRemarkList(ResRemark resRemark,Integer pageNum,Integer pageSize)
    {
        //1、PageHelper开始分页，传入第几页和每页多少条记录两个参数
        PageHelper.startPage(pageNum, pageSize);
        //2、数据库进行查询
        List<ResRemark> resRemarks = resRemarkMapper.selectResRemarkList(resRemark);
        //3、对返回值进行判断
        if (resRemarks.size()==0){
            return null;
        }
        //4、对查询的结果进行封装
        PageInfo<ResRemark> thumbupPageInfo = new PageInfo<>(resRemarks);
        PageResult pageResult = PageUtils.getPageResult(thumbupPageInfo);

        return pageResult;
    }

    /**
     * 新增评价

     * 
     * @param resRemark 评价

     * @return 结果
     */
    @Override
    public int insertResRemark(ResRemark resRemark)
    {
        resRemark.setRemarkTime(new Date(System.currentTimeMillis()));
        resRemark.setBuyTime(new Date(System.currentTimeMillis()));
        return resRemarkMapper.insertResRemark(resRemark);
    }

    /**
     * 修改评价

     * 
     * @param resRemark 评价

     * @return 结果
     */
    @Override
    public int updateResRemark(ResRemark resRemark)
    {

        resRemark.setRemarkTime(new Date(System.currentTimeMillis()));
        resRemark.setBuyTime(new Date(System.currentTimeMillis()));
        return resRemarkMapper.updateResRemark(resRemark);
    }

    /**
     * 批量删除评价

     * 
     * @param ids 需要删除的评价
主键
     * @return 结果
     */
    @Override
    public int deleteResRemarkByIds(Long[] ids)
    {
        return resRemarkMapper.deleteResRemarkByIds(ids);
    }

    /**
     * 删除评价
信息
     * 
     * @param id 评价
主键
     * @return 结果
     */
    @Override
    public int deleteResRemarkById(Long id)
    {
        return resRemarkMapper.deleteResRemarkById(id);
    }
}
